//
//  HRStatusToolBar.swift
//  microBlog
//
//  Created by HR_W on 16/5/25.
//  Copyright © 2016年 admin. All rights reserved.
//

import UIKit
import SnapKit

class HRStatusToolBar: UIView {
    
    var statusViewModel: HRStatusViewModel? {
    
        didSet {
        repostBtn.setTitle(statusViewModel?.repostsText, forState: .Normal)
        commentBnt.setTitle(statusViewModel?.commentText, forState: .Normal)
        ohYeahBtn.setTitle(statusViewModel?.attitudesText, forState: .Normal)
        
        }
    
    }
    

    override init(frame: CGRect) {
        super.init(frame: frame)
      backgroundColor = UIColor.whiteColor()
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //设置界面
    private func setupUI() {
    
        addChildBtn(repostBtn, title: "转发", imageName: "timeline_icon_retweet")
        addChildBtn(commentBnt, title: "评论", imageName: "timeline_icon_comment")
        addChildBtn(ohYeahBtn, title: "攒", imageName: "timeline_icon_like")
        
        //子视图等宽平分父视图
        repostBtn.snp_makeConstraints { (make) in
            make.left.top.bottom.equalTo(self)
        }
        
        commentBnt.snp_makeConstraints { (make) in
            make.left.equalTo(repostBtn.snp_right)
            make.top.bottom.equalTo(repostBtn)
            make.width.equalTo(repostBtn.snp_width)
        }
        ohYeahBtn.snp_makeConstraints { (make) in
            make.left.equalTo(commentBnt.snp_right)
            make.top.bottom.equalTo(commentBnt)
            make.right.equalTo(self)
            make.width.equalTo(repostBtn.snp_width)
        }
        
        
        let sepView1 = lineView()
        let sepView2 = lineView()
        let width = 1 / UIScreen.mainScreen().scale
        
        addSubview(sepView1)
        addSubview(sepView2)
        
        sepView1.snp_makeConstraints { (make) in
            make.left.equalTo(commentBnt.snp_left)
            make.centerY.equalTo(self.snp_centerY)
            //黄金分割比  1 : 0.618
            make.height.equalTo(self.snp_height).multipliedBy(0.4)
            make.width.equalTo(width)
        }
        
        sepView2.snp_makeConstraints { (make) in
            make.left.equalTo(commentBnt.snp_right)
            make.centerY.equalTo(self.snp_centerY)
            //黄金分割比  1 : 0.618
            make.height.equalTo(self.snp_height).multipliedBy(0.4)
            make.width.equalTo(width)
        }
    
    }
        //分隔线
    private func lineView() ->UIView{
    
        let line = UIView()
        line.backgroundColor = UIColor.blueColor()
        
        return line
    
    }

    private func addChildBtn(btn: UIButton,title: String,imageName: String){
        btn.setTitle(title, forState: .Normal)
        btn.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        btn.titleLabel?.font = UIFont.systemFontOfSize(10)
        btn.setImage(UIImage(named: imageName), forState: .Normal)
        btn.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        btn.sizeToFit()
        self.addSubview(btn)
    
    }
    
    //懒加载控件
    private lazy var repostBtn: UIButton = UIButton()
    
    private lazy var commentBnt: UIButton = UIButton()
    
    private lazy var ohYeahBtn: UIButton = UIButton()
    
}


